﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;


namespace MVCWeb.Models
{

    public class TvModelPrtials
    {
        [Required]
        [DisplayName("Display")]
        public int Display { get; set; }


        [Required]
        [DisplayName("Make")]
        public int Make { get; set; }

        [Required]
        [DisplayName("Size")]
        public int Size { get; set; }

        [Required]
        [DisplayName("Resolution")]
        public int Resolution { get; set; }

        [Required]
        [DisplayName("Refresh")]
        public int Refresh { get; set; }


        [Required]
        [DisplayName("Shipping")]
        public int Shipping { get; set; }

        [Required]
        [DisplayName("ProductID")]
        public int product_id { get; set; }

        [Required]
        [DisplayName("DisplayType")]
        public string display_type { get; set; }

        [Required]
        [DisplayName("MakeType")]
        public string make_type { get; set; }

        [Required]
        [DisplayName("SizeType")]
        public string size_type { get; set; }

        [Required]
        [DisplayName("ResType")]
        public string res_type { get; set; }

        [Required]
        [DisplayName("RefreshType")]
        public string refresh_type { get; set; }

        [Required]
        [DisplayName("Price")]
        public double price { get; set; }


        [Required]
        [DisplayName("ShipType")]
        public string ship_type { get; set; }

        [Required]
        [DisplayName("Amount Of Selling")]
        public int num_sales { get; set; }

        [Required]
        [DisplayName("Amount Of Stock")]
        public int num_stocked { get; set; }
    }

    public class WebmasterModel
    {
        [Required]
        [DisplayName("Customer ID")]
        public int customer_id { get; set; }

        [Required]
        [DisplayName("email")]
        public string email { get; set; }

        [Required]
        [DisplayName("First Name")]
        public string first_name { get; set; }

        [Required]
        [DisplayName("Last Name")]
        public string last_name { get; set; }

        [Required]
        [DisplayName("Street Address")]
        public string address { get; set; }

        [Required]
        [DisplayName("City")]
        public string city { get; set; }

        [Required]
        [DisplayName("State")]
        public string state { get; set; }

        [Required]
        [DisplayName("Zip")]
        public int zip { get; set; }

        [Required]
        [DisplayName("Permission")]
        public int permission { get; set; }

        [Required]
        [DisplayName("Block Status")]
        public int blockuser { get; set; }

    }


    public static class WebMasterClientServices
    {////////////////

        public static TvModelPrtials DTO_TO_PSL(SLTv.Product product)
        {
            TvModelPrtials SLProduct = new Models.TvModelPrtials();


            SLProduct.product_id = product.product_id;
            SLProduct.display_type = product.display_type;
            SLProduct.make_type = product.make_type;
            SLProduct.size_type = product.size_type;
            SLProduct.refresh_type = product.refresh_type;
            SLProduct.res_type = product.res_type;
            SLProduct.price = product.price;
            SLProduct.ship_type = product.shipping_type;
            SLProduct.num_sales = product.num_sales;
            SLProduct.num_stocked = product.num_stocked;

            return SLProduct;
        }

        public static List<TvModelPrtials> OutOfStockDetail()
        {
            SLTv.ISLTv SLTV = new SLTv.SLTvClient();
            List<TvModelPrtials> TOPFIVE = new List<TvModelPrtials>();
            string[] errors = new string[0];

            SLTv.Product[] product = SLTV.GetOutStockDetail(ref errors);

            if (product != null)
            {
                foreach (SLTv.Product sigleTV in product)
                {
                    TvModelPrtials tranTv = DTO_TO_PSL(sigleTV);
                    TOPFIVE.Add(tranTv);
                }
            }
            return TOPFIVE;
        
        
        }

        public static List<TvModelPrtials> GetTopFive()
        {

            SLTv.ISLTv SLTV = new SLTv.SLTvClient();
            List<TvModelPrtials> TOPFIVE = new List<TvModelPrtials>();
            string[] errors = new string[0];

            SLTv.Product[] product = SLTV.GetTopFive(ref errors);

            foreach (SLTv.Product sigleTV in product)
            {
                TvModelPrtials tranTv = DTO_TO_PSL(sigleTV);
                TOPFIVE.Add(tranTv);
            }
            return TOPFIVE;

        }
      


        /////////////

        


        //block user
        public static void BlockUser(int userID)
        {
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            string[] errors = new string[0];
            SLCust.BlockUser(userID, ref errors);
        }

        //unblock user
        public static void UnblockUser(int userID)
        {
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            string[] errors = new string[0];
            SLCust.UnBlockCustomer(userID, ref errors);         
        }

        //change permission
        public static void ChangePermission(CustomerModel cust)
        {
            SLCustomer.BaseCustomer customer = DTO_to_SL(cust);

            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            string[] errors = new string[0];
            SLCust.ChangePermission(customer, ref errors);
        }
        //delete customer
        public static void DeleteCustomer(int id)
        {
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            string[] errors = new string[0];
            SLCust.DeleteCustomer(id, ref errors);
        }

        //get customer details
        public static CustomerModel GetCustomerDetails(int id)
        {
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            string[] errors = new string[0];

            SLCustomer.BaseCustomer cust = SLCust.GetCustomerDetail(id, ref errors);

            return DTO_to_PL(cust);
        }
        /*
            Webmaster page part
         */

        //change back
        public static List<WebmasterModel> GetBlockUserInfor()
        {

            SLCustomer.ISLCustomer infor = new SLCustomer.SLCustomerClient();
            List<WebmasterModel> inforList = new List<WebmasterModel>();
            string[] erros = new string[0];

            SLCustomer.BaseCustomer[] users = infor.GetBlockUserInfor(ref erros);
            if (users != null)
            {
                foreach (SLCustomer.BaseCustomer b in users)
                {
                    WebmasterModel people = DTO_to_WB(b);
                    inforList.Add(people);
                }
            }
            else {
                return null;
            }
            return inforList;
        }

        public static List<WebmasterModel> GetWebMasterInfor()
        {

            SLCustomer.ISLCustomer infor = new SLCustomer.SLCustomerClient();
            List<WebmasterModel> inforList = new List<WebmasterModel>();
            string[] erros = new string[0];

            SLCustomer.BaseCustomer[] users = infor.GetWebMasterInfor(ref erros);

            foreach (SLCustomer.BaseCustomer b in users)
            {
                WebmasterModel people = DTO_to_WB(b);
                inforList.Add(people);
            }
            return inforList;
        } 
        /// <summary>
        /// //
        /// </summary>
        /// <returns></returns>
        public static int GetTotalUser()
        {
            string[] errors = new string[0];
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
           int number  = SLCust.GetTotalUser(ref errors);
           return number;
        }

        public static int GetTotalBlockUser()
        {
            string[] errors = new string[0];
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            int number = SLCust.GetTotalBlock(ref errors);
            return number;
        }

        public static int GetTotalWebMaster() 
        {
            string[] errors = new string[0];
            SLCustomer.ISLCustomer SLCust = new SLCustomer.SLCustomerClient();
            int number = SLCust.GetTotalWebMaster(ref errors);
            return number;
        } 

    




        /*END OF WEB MASTER PAGE*/


        //DTO to PL
        private static CustomerModel DTO_to_PL(SLCustomer.BaseCustomer customer)
        {
            CustomerModel PLCustomer = new Models.CustomerModel();
            PLCustomer.customer_id = customer.customer_id;
            PLCustomer.email = customer.email;
            PLCustomer.first_name = customer.first_name;
            PLCustomer.last_name = customer.last_name;
            PLCustomer.address = customer.address;
            PLCustomer.city = customer.city;
            PLCustomer.state = customer.state;
            PLCustomer.zip = customer.zip;
            PLCustomer.permission = customer.webmaster;
            PLCustomer.blockuser = customer.blockuser;

            return PLCustomer;
        }

        private static WebmasterModel DTO_to_WB(SLCustomer.BaseCustomer customer)
        {
            WebmasterModel PLCustomer = new Models.WebmasterModel();
            PLCustomer.customer_id = customer.customer_id;
            PLCustomer.email = customer.email;
            PLCustomer.first_name = customer.first_name;
            PLCustomer.last_name = customer.last_name;
            PLCustomer.address = customer.address;
            PLCustomer.city = customer.city;
            PLCustomer.state = customer.state;
            PLCustomer.zip = customer.zip;
            PLCustomer.permission = customer.webmaster;
            PLCustomer.blockuser = customer.blockuser;

            return PLCustomer;
        }

        //DTO to SL
        private static SLCustomer.BaseCustomer DTO_to_SL(CustomerModel customer)
        {
            SLCustomer.BaseCustomer SLCust = new MVCWeb.SLCustomer.BaseCustomer();
            SLCust.customer_id = customer.customer_id;
            SLCust.email = customer.email;
            SLCust.first_name = customer.first_name;
            SLCust.last_name = customer.last_name;
            SLCust.address = customer.address;
            SLCust.city = customer.city;
            SLCust.state = customer.state;
            SLCust.zip = customer.zip;
            SLCust.webmaster = customer.permission;
            SLCust.blockuser = customer.blockuser;

            return SLCust;
        }


    }
}